<script type="text/javascript" src="<?=PATH_URL.'static/js/admin/jquery.slugit.js'?>"></script>
<script type="text/javascript">
$(document).ready( function() {
	$("#titleVnAdmincp").slugIt({
		events: 'keyup blur',
		output: '#slugAdmincp',
		space: '-'
	});
});

function save(){
	var options = {
		beforeSubmit:  showRequest,  // pre-submit callback
		success:       showResponse  // post-submit callback
    };
	$('#frmManagement').ajaxSubmit(options);
}

function showRequest(formData, jqForm, options) {
	var form = jqForm[0];
	// if(form.titleAdmincp.value == '' || form.descAdmincp.value == '' || $('#contentAdmincp').val() == '<br>' || $('#contentAdmincp').val() == ''){
	// 	$('#txt_error').html('Please enter information!!!');
	// 	$('#loader').fadeOut(300);
	// 	show_perm_denied();
	// 	return false;
	// }
	if(form.titleAdmincp.value == ''){
		$('#loader').hide();
		alert('Bạn chưa nhập tên tài liệu.');
		show_content('vn');
		$('input[name="titleAdmincp"]').addClass('error-fr');
		return false;
	}
}

function showResponse(responseText, statusText, xhr, $form) {
	if(responseText=='success'){
		location.href=root+"admincp/"+module+"/#/save";
	}

	if(responseText=='error-title-exists'){
		$('#txt_error').html('Title already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		$('#titleAdmincp').focus();
		return false;
	}

	if(responseText=='permission-denied'){
		show_perm_denied();
	}
}

function show_content(lang){
	$('.w_content').hide();
	$('#'+lang).show();
        $('#img_'+lang).css('width','20px');
        if(lang=='vn'){
           $('#img_en').css('width','17px');
           $('#img_gr').css('width','17px');
        }
        else if(lang=='en'){
           $('#img_vn').css('width','17px');
           $('#img_gr').css('width','17px');
        }
        else{
           $('#img_vn').css('width','17px');
           $('#img_en').css('width','17px');
        }
}
</script>
<div class="gr_perm_error" style="display:none;">
	<p><strong>FAILURE: </strong><span id="txt_error">Permission Denied.</span></p>
</div>
<div class="table">
	<div class="head_table"><div class="head_title_edit"><?=$module?></div></div>
	<div class="clearAll"></div>

	<form id="frmManagement" action="<?=PATH_URL.'admincp/'.$module.'/save/'?>" method="post" enctype="multipart/form-data">
	<input type="hidden" value="<?=$id?>" name="hiddenIdAdmincp" />
	<div class="row_text_field_first">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Status:</td>
				<td class="right_text_field"><input <?php if(isset($result->status)){ if($result->status==1){ ?>checked="checked"<?php }}else{ ?>checked="checked"<?php } ?> type="checkbox" class="custom_chk" name="statusAdmincp" /></td>
			</tr>
		</table>
	</div>
	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Title:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->title)) { print $result->title; }else{ print '';} ?>" type="text" name="titleAdmincp" id="titleAdmincp" /></td>
			</tr>
		</table>
	</div>
	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Upload file:</td>
				<td class="right_text_field"><input type="file" name="fileAdmincp" id="fileAdmincp"/>

				</td>
			</tr>
		</table>
	</div>
	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">User can download:</td>
				<td class="right_text_field">
					<?php if(isset($result->groups)) { $result_groups = explode(',', $result->groups);	} ?>
					<?php if(isset($user_groups)) {
							foreach ($user_groups as $group) {
				  	?>
				  	<div class="group" style='width: auto; float: left;'>
				  		<input type='checkbox' name='group[]' <?php if(isset($result_groups) && in_array($group->id,$result_groups,true)) { print "checked='checked'";} ?> value='<?=$group->id?>'><span style='margin: 0 25px 0 5px; vertical-align:top;'><?=$group->name_vi?></span>
				  	</div>
					<?php	 }}?>
				</td>
			</tr>
		</table>
	</div>
	</form>
</div>
